[id].vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 导航栏 -->
  5. <HomePageNavigation></HomePageNavigation>
  6. <!-- 列表页广告一 -->
  7. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  8. <!-- 资讯列表 -->
  9. <div class="newsDetail">
  10. <div class="inner">
  11. <div class="innerLeft">
  12. <!-- 面包屑导航 -->
  13. <div class="breadcrumb">
  14. <div class="inner">
  15. <span class="location">当前位置:</span>
  16. <el-breadcrumb :separator-icon="ArrowRight">
  17. <el-breadcrumb-item>
  18. <NuxtLink to="/">首页</NuxtLink>
  19. </el-breadcrumb-item>
  20. <!-- <el-breadcrumb-item v-if="parent_children_count > 0">
  21. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  22. </el-breadcrumb-item> -->
  23. <el-breadcrumb-item v-else">
  24. <NuxtLink :to="`/${parent_pinyin}/list-1.html`"> {{ routLevelTitle }}</NuxtLink>
  25. </el-breadcrumb-item>
  26. <el-breadcrumb-item>{{ getTitleLength(routeNewsTtitle,20) }}</el-breadcrumb-item>
  27. </el-breadcrumb>
  28. </div>
  29. </div>
  30. <div class="LeftTop">
  31. <h1>{{ newsDetail.title }}</h1>
  32. <p>
  33. 来源: <span>{{ newsDetail.copyfrom }}</span>
  34. 作者: <span>{{ newsDetail.author }}</span>
  35. 发布时间: <span>{{ time }}</span>
  36. </p>
  37. </div>
  38. <div
  39. class="leftBottom"
  40. v-html="newsDetail.content"
  41. v-if="newsDetail.content"
  42. @click="openPreview">
  43. </div>
  44. <div v-if="previewVisible" class="preview-modal" @click="closePreview">
  45. <img :src="selectedImage" alt="Preview">
  46. </div>
  47. <!-- 免责声明: -->
  48. <div class="disclaimer" v-if="newsDetail.copyfrom == '本网'">
  49. <p>原文链接:{{ newsDetail.fromurl }}</p>
  50. <p>[免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。</p>
  51. </div>
  52. <div v-if="articleChoice">
  53. <HomeSurveyvote></HomeSurveyvote>
  54. </div>
  55. </div>
  56. <div class="innerRight">
  57. <!-- 热点资讯1 -->
  58. <div class="hotList1">
  59. <DetailHotNews></DetailHotNews>
  60. </div>
  61. <!-- 热点资讯2 -->
  62. <div class="hotList2">
  63. <DetailHotNews2></DetailHotNews2>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. <!-- 页面底部 -->
  69. <HomeFoot1></HomeFoot1>
  70. </template>
  71. <script setup>
  72. //1.页面依赖 start ---------------------------------------->
  73. import { onMounted } from 'vue'
  74. import { ElBreadcrumb, ElBreadcrumbItem} from 'element-plus'
  75. import { ArrowRight } from '@element-plus/icons-vue'
  76. //1.页面依赖 end ---------------------------------------->
  77. //2.页面路径 start ---------------------------------------->
  78. const targetSegment = getRoutePath(1);
  79. let routeId;
  80. //通过导航路径反向查询导航id
  81. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  82. method: 'GET',
  83. query: {
  84. 'pinyin': targetSegment,
  85. },
  86. });
  87. if(getRouteId.code == 200){
  88. routeId = getRouteId.data.category_id
  89. }else{
  90. console.log("错误位置:获得页面路径")
  91. }
  92. //2.页面路径 start ---------------------------------------->
  93. //3.面包屑 start ---------------------------------------->
  94. const route = useRoute();
  95. const articleId = parseInt(route.params.id); //获得该页面的id
  96. //3.1 获得父级栏目的名称、id
  97. const parent_name = ref([]);
  98. const parent_id = ref([]);
  99. const parent_pinyin = ref("");
  100. const parent_children_count = ref(0)
  101. let getParentNav = async () => {
  102. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  103. method: 'GET',
  104. query: {
  105. 'catid': routeId
  106. },
  107. });
  108. if (listData.code == 200) {
  109. console.log(778899)
  110. console.log(listData.data)
  111. parent_name.value = listData.data.alias;
  112. parent_id.value = listData.data.parent_id;
  113. parent_pinyin.value = listData.data.aLIas_pinyin;
  114. parent_children_count.value = listData.data.children_count;
  115. } else {
  116. console.log("错误位置:获取面包屑导航")
  117. }
  118. }
  119. getParentNav();
  120. //3.页面依赖 end ---------------------------------------->
  121. //4.页面数据 start ---------------------------------------->
  122. //4.1 资讯详情
  123. const newsDetail = ref({})
  124. const routeNewsTtitle = ref("");
  125. //4.2 发布日期
  126. const time = ref("");
  127. //4.3 路径
  128. const routLevelTitle = ref("");
  129. const routLevelId = ref("");
  130. //4.4 是否展示投票
  131. const articleChoice = ref(false);
  132. //4.5 获取详情
  133. async function getPageData() {
  134. const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  135. method: 'GET',
  136. query: {
  137. 'articleid': articleId
  138. },
  139. });
  140. if(mkdata.code==200){
  141. //判断是否显示投票
  142. if(mkdata.data.is_survey==1){
  143. console.log("本篇文章含有投票!")
  144. articleChoice.value = true;
  145. }
  146. //获取内容
  147. newsDetail.value = mkdata.data;
  148. //获取路径
  149. routLevelTitle.value = newsDetail.value.cat_name;
  150. routLevelId.value = newsDetail.value.category_id;
  151. //获取发布时间
  152. time.value = newsDetail.value.updated_at.split(' ')[0];
  153. //修正标题长度
  154. if (newsDetail.value.title.length >= 30) {
  155. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  156. } else {
  157. routeNewsTtitle.value = newsDetail.value.title
  158. }
  159. }else{
  160. console.log("错误位置:获取详情内容")
  161. }
  162. }
  163. getPageData();
  164. //4.页面数据 end ---------------------------------------->
  165. //5.广告 start ---------------------------------------->
  166. let adImg1 = ref([]);
  167. onMounted(async () => {
  168. const { $webUrl, $CwebUrl } = useNuxtApp();
  169. //广告1
  170. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_detail_0001`
  171. const responseAd1 = await fetch(url, {
  172. headers: {
  173. 'Content-Type': 'application/json',
  174. 'Userurl': $CwebUrl,
  175. 'Origin': $CwebUrl
  176. }
  177. });
  178. const resultAd1 = await responseAd1.json();
  179. adImg1.value = resultAd1.data[0];
  180. })
  181. //5.广告 end ---------------------------------------->
  182. //6.设置seo信息 start---------------------------------------->
  183. const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  184. method: 'GET',
  185. query: {
  186. 'articleid': articleId
  187. },
  188. });
  189. if(setData.code==200){
  190. let seoTitle = setData.data.title;
  191. let seoDescription = setData.data.introduce;
  192. let seoKeywords = setData.data.keyword;
  193. let seoSuffix = setData.data.suffix;
  194. let seoName = setData.data.website_name;
  195. useSeoMeta({
  196. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  197. meta: [
  198. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  199. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix , tagPriority: 10 }
  200. ]
  201. });
  202. }else{
  203. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  204. console.log("错误位置:设置详情页面SEO数据")
  205. console.log("后端错误反馈:",setData.message)
  206. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  207. }
  208. //6.设置seo信息 end---------------------------------------->
  209. //8.页面图片放大 start---------------------------------------->
  210. const previewVisible = ref(false)
  211. const selectedImage = ref(' ')
  212. const openPreview = (event) => {
  213. if (event.target.tagName === 'IMG') {
  214. selectedImage.value = event.target.src;
  215. previewVisible.value = true;
  216. }
  217. }
  218. const closePreview = () => {
  219. previewVisible.value = false;
  220. }
  221. //8.页面图片放大 end---------------------------------------->
  222. </script>
  223. <style lang="less" scoped>
  224. @import url('@/assets/css/detail.less');
  225. </style>